package 笔试.顺丰;

import java.util.Arrays;
import java.util.Scanner;

public class Demo1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int n = sc.nextInt();
        int[][] harm = new int[n][5];
        int[] score = new int[n];
        int[] copy = new int[n];
        for (int i = 0; i < n; i++) {
            harm[i][0] = sc.nextInt();
            harm[i][1] = sc.nextInt();
            harm[i][2] = sc.nextInt();
            harm[i][3] = sc.nextInt();
            harm[i][4] = sc.nextInt();
            score[i] = a*harm[i][0]+b*harm[i][1]+c* harm[i][2]+d*harm[i][3]+e*harm[i][4];

        }
        for (int i = 0; i < n; i++) {
            copy[i] = score[i];
        }
        Arrays.sort(copy);
        int max = copy[copy.length-1];
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (score[i]==max){
                count++;
            }
        }
        System.out.println(max);
        System.out.println(count);
        for (int i = 0; i < n; i++) {
            if(score[i]==max){
                System.out.println(i+1);
            }
        }
    }
}
